home *** CD-ROM | disk | FTP | other *** search
- property pWorld, pCamera, pName, pScale, plFaces, pBuilt, plTextures, plShaders, pModelResource, pModel
-
- on new me, tWorld, tName, tCamera
- plFaces = [:]
- plFaces[#front] = 0
- plFaces[#back] = 0
- plFaces[#left] = 0
- plFaces[#right] = 0
- plFaces[#up] = 0
- plFaces[#down] = 0
- pBuilt = 0
- pName = tName
- pWorld = member(tWorld)
- pScale = 1.0
- if voidp(tCamera) then
- pCamera = 1
- else
- pCamera = tCamera
- end if
- return me
- end
-
- on Destroy me
- if not pBuilt then
- return 0
- end if
- pWorld.deleteModel(pModel)
- pWorld.deleteModelResource(pModelResource)
- repeat with a in plShaders
- pWorld.deleteShader(a)
- end repeat
- repeat with a in plTextures
- pWorld.deleteTexture(a)
- end repeat
- pBuilt = 0
- return 1
- end
-
- on update me
- if pBuilt then
- pModel.transform.position = pWorld.camera[pCamera].transform.position
- return 1
- else
- return 0
- end if
- end
-
- on SetFace me, tFace, tTexture, tlOrientation
- if pBuilt then
- return 0
- end if
- if [#front, #back, #left, #right, #up, #down].getOne(symbol(tFace)) = 0 then
- return 0
- end if
- tm = member(tTexture)
- tXOffset = 0.5 / tm.rect.width
- tYOffset = 0.5 / tm.rect.height
- tlUV = [[1.0 - tXOffset, 1.0 - tYOffset], [tXOffset, 1.0 - tYOffset], [tXOffset, tYOffset], [1.0 - tXOffset, tYOffset]]
- if not listp(tlOrientation) then
- tlOrientation = [tlOrientation]
- end if
- repeat with a in tlOrientation
- case a of
- #rotatecw:
- tlUV.add(tlUV[1].duplicate())
- tlUV.deleteAt(1)
- #rotateccw:
- tlUV.addAt(1, tlUV[4].duplicate())
- tlUV.deleteAt(5)
- #fliphorizontal:
- tlUV = [tlUV[2], tlUV[1], tlUV[4], tlUV[3]]
- #flipvertical:
- tlUV = [tlUV[4], tlUV[3], tlUV[2], tlUV[1]]
- end case
- end repeat
- plFaces[tFace] = [tm, tlUV]
- return 1
- end
-
- on SetSize me, tScale
- if pBuilt or (tScale <= 0.0) then
- return 0
- end if
- pScale = tScale
- return 1
- end
-
- on build me
- if pBuilt then
- return 0
- end if
- repeat with a = 1 to 6
- if plFaces[a] = 0 then
- return 0
- end if
- end repeat
- plShaders = []
- plTextures = []
- repeat with a = 1 to 6
- tFace = string(plFaces.getPropAt(a))
- tm = plFaces[a][1]
- tName = tm.name
- tTextureFound = 0
- tTextures = pWorld.texture.count
- repeat with b = 1 to tTextures
- if pWorld.texture[b].name = tName then
- tTextureFound = 1
- end if
- end repeat
- if tTextureFound then
- tTexture = pWorld.texture(tName)
- else
- tTexture = pWorld.newTexture(tName, #fromCastMember, tm)
- tTexture.renderFormat = #rgba8880
- tTexture.nearFiltering = 1
- tTexture.quality = #high
- end if
- plTextures.add(tTexture)
- tShader = pWorld.newShader(pName && tFace && "'" & tName & "'", #standard)
- tShader.texture = tTexture
- tShader.textureMode = #none
- tShader.textureRepeat = 0
- tShader.emissive = rgb(255, 255, 255)
- tShader.ambient = rgb(0, 0, 0)
- tShader.diffuse = rgb(0, 0, 0)
- tShader.specular = rgb(0, 0, 0)
- plShaders.add(tShader)
- end repeat
- tlVertices = [vector(-pScale, -pScale, pScale), vector(pScale, -pScale, pScale), vector(pScale, -pScale, -pScale), vector(-pScale, -pScale, -pScale), vector(-pScale, pScale, pScale), vector(pScale, pScale, pScale), vector(pScale, pScale, -pScale), vector(-pScale, pScale, -pScale)]
- tlTextureUVs = []
- repeat with a = 1 to 6
- repeat with b in plFaces[a][2]
- tlTextureUVs.add(b.duplicate())
- end repeat
- end repeat
- tlFaces = []
- repeat with a = 1 to 6
- case a of
- 1:
- tlFaceVertices = [[7, 8, 3], [8, 4, 3]]
- 2:
- tlFaceVertices = [[5, 6, 1], [6, 2, 1]]
- 3:
- tlFaceVertices = [[8, 5, 4], [5, 1, 4]]
- 4:
- tlFaceVertices = [[6, 7, 2], [7, 3, 2]]
- 5:
- tlFaceVertices = [[6, 5, 7], [5, 8, 7]]
- 6:
- tlFaceVertices = [[3, 4, 2], [4, 1, 2]]
- end case
- tUVOffset = (a - 1) * 4
- tlFace = [plShaders[a], tlFaceVertices[1], [1, 2, 4] + tUVOffset]
- tlFaces.add(tlFace.duplicate())
- tlFace = [plShaders[a], tlFaceVertices[2], [2, 3, 4] + tUVOffset]
- tlFaces.add(tlFace.duplicate())
- end repeat
- pModelResource = pWorld.newMesh(pName, 12, 8, 0, 0, 24)
- pModelResource.vertexList = tlVertices
- pModelResource.textureCoordinateList = tlTextureUVs
- repeat with a = 1 to 12
- tlFace = tlFaces[a]
- pModelResource.face[a].shader = tlFace[1]
- pModelResource.face[a].vertices = tlFace[2]
- pModelResource.face[a].textureCoordinates = tlFace[3]
- end repeat
- pModelResource.generateNormals(#flat)
- pModelResource.build()
- pModel = pWorld.newModel(pName, pModelResource)
- pModel.addToWorld()
- pBuilt = 1
- return 1
- end
-